//
//  BDJTabBar.m
//  BuDeJie
//
//  Created by TFAppleWork-Summer on 2018/3/20.
//  Copyright © 2018年 TFAppleWork-Summer. All rights reserved.
//

#import "BDJTabBar.h"

@interface BDJTabBar()

@property (nonatomic, strong) UIButton *plusBtn;

@end

@implementation BDJTabBar

-(UIButton*)plusBtn{
    if (!_plusBtn) {
      
        _plusBtn = [[UIButton alloc] init];
        [_plusBtn setImage:[UIImage imageNamed:@"tabbarIconPost"] forState:UIControlStateNormal];
        [_plusBtn setImage:[UIImage imageNamed:@"tabbarIconPost"] forState:UIControlStateHighlighted];
         [_plusBtn sizeToFit];
        [self addSubview:self.plusBtn];
       
    }
    return _plusBtn;
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    CGFloat btnW = self.bounds.size.width/(self.items.count + 1);
    CGFloat btnH = self.bounds.size.height;
    CGFloat x = 0;
    NSInteger i = 0;
    for (UIView * tabbarButton in  self.subviews) {
        if ([tabbarButton isKindOfClass:NSClassFromString(@"UITabBarButton")])
        {
            if (i == 2) {
                i += 1;
            }
            x = i * btnW;
            tabbarButton.frame = CGRectMake(x, 0, btnW, btnH);
            i++;
        }
    }
    
    // 调整发布按钮的位置
    self.plusBtn.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5);
}

@end
